package com.beeantec.jnrerc.modules.leaderboard.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beeantec.jnrerc.core.api.ApiRest;
import com.beeantec.jnrerc.core.api.controller.BaseController;
import com.beeantec.jnrerc.core.enums.JobEnum;
import com.beeantec.jnrerc.dto.DepartDTO;
import com.beeantec.jnrerc.dto.response.LeaderBoardRespDTO;
import com.beeantec.jnrerc.entity.Member;
import com.beeantec.jnrerc.modules.member.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags={"排行榜"})
@RestController
@RequestMapping("/api/leaderboard")
public class LeaderBoardController extends BaseController {

    @Autowired
    MemberService memberService;
    /**
     * 获取周榜
     * @param type
     * @return
     */
    @ApiOperation(value = "获取排行榜")
    @RequestMapping(value = "/get", method = { RequestMethod.GET})
    public ApiRest<List<LeaderBoardRespDTO>> getWeek(@RequestParam("boardType") Integer boardType,@RequestParam("type") Integer type) {
        List<LeaderBoardRespDTO> list = new ArrayList<>();
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        if (type==0){
            queryWrapper.lambda().orderByDesc(Member::getIntegral).ne(Member::getMemberId,0).eq(Member::getMemberType,1).eq(Member::getJobId, JobEnum.WORKER.getCode());
        }else {
            queryWrapper.lambda().orderByDesc(Member::getCharm).ne(Member::getMemberId,0).eq(Member::getMemberType,1).eq(Member::getJobId, JobEnum.WORKER.getCode());
        }
       List<Member> memberList = memberService.getBaseMapper().selectList(queryWrapper);
       for (Member member:memberList){
           LeaderBoardRespDTO leaderBoardRespDTO = new LeaderBoardRespDTO();
           leaderBoardRespDTO.setHead(member.getAvatarUrl());
           leaderBoardRespDTO.setName(member.getNickName());
           leaderBoardRespDTO.setMemberId(member.getMemberId());
           if (type==0){
               leaderBoardRespDTO.setCount(member.getIntegral());
           }else {
               leaderBoardRespDTO.setCount(member.getCharm());
           }
           list.add(leaderBoardRespDTO);
       }
        return super.success(list);
    }


}
